{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a177b610",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"logfile.log\",\"a\") as logfile:\n",
    "    logfile.write(\"aaa\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4cb07125",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aaa\n"
     ]
    }
   ],
   "source": [
    "with open(\"logfile.log\",\"r\") as logfile:\n",
    "    text = logfile.read();\n",
    "    print(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "66ce4183",
   "metadata": {},
   "outputs": [],
   "source": [
    "logfile = open(\"logfile.log\", \"a\")\n",
    "\n",
    "logfile.write(\"bbb\") \n",
    "\n",
    "# 刷新缓冲区\n",
    "\n",
    "logfile.flush()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b22199ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "logfile.close()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
